<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: css_styler.php 421 2014-01-19 11:34:20Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 421 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-19 11:34:20 +0000 (Sun, 19 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License

CREATE TABLE  `mercari_css_definition` (
`attribut_name` VARCHAR( 64 ) NOT NULL ,
`attribute` TEXT NOT NULL ,
`last_modified` DATETIME NOT NULL ,
PRIMARY KEY (  `attribut_name` )
) ENGINE = INNODB;

body {color: ; background: ;}
a {color: ; text-decoration: ;}
a:hover {color: ; text-decoration: ;}
h1 {font-size: ; font-weight: ; color: ;}

.box {background: ; margin: ;}
.box_head {color: ; margin: ;}
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
//echo_e($_GET, 'E');
//echo_e(href_link('css_styler.php'));

if($_GET['action']) {
	switch($_GET['action']) {
		case 'save_config':

			$configuration = $db->db_query("SELECT
												configuration_key
											FROM
												".TABLE_CONFIGURATION."
											WHERE
												configuration_group_id = '23'
											AND
												configuration_key NOT LIKE '%_CART_%'
											ORDER BY
												sort_order");
			while(!$configuration->EOF) {
				$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = '".$_POST[$configuration->fields['configuration_key']]."' WHERE configuration_key = '".$configuration->fields['configuration_key']."'");
				$configuration->MoveNext();
			}
			deleteCacheFolders();
			@unlink(DIR_FS_CATALOG.'cache/mercari_buttons.css');
			include_once(DIR_FS_CATALOG.'css_styler.php');
      redirect(href_link('css_styler.php'));
	    break;
	    	
	   case 'save_cart_config':

			$configuration = $db->db_query("SELECT
												configuration_key
											FROM
												".TABLE_CONFIGURATION."
											WHERE
												configuration_group_id = '23'
											AND
												configuration_key LIKE '%_CART_%'
											ORDER BY
												sort_order");
			while(!$configuration->EOF) {
				$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = '".$_POST[$configuration->fields['configuration_key']]."' WHERE configuration_key = '".$configuration->fields['configuration_key']."'");
				$configuration->MoveNext();
			}
			deleteCacheFolders();
			@unlink(DIR_FS_CATALOG.'cache/mercari_buttons.css');
			include_once(DIR_FS_CATALOG.'css_styler.php');
      redirect(href_link('css_styler.php'));
    	break;
	}
}

$cfg_group = $db->db_query("SELECT
								configuration_group_title
							FROM
								".TABLE_CONFIGURATION_GROUP."
							WHERE
								configuration_group_id = '23'");

$configuration = $db->db_query("SELECT
									configuration_key,
									configuration_id,
									configuration_value,
									use_function,
									set_function
								FROM
									".TABLE_CONFIGURATION."
								WHERE
									configuration_group_id = '23'
								ORDER BY
									sort_order");
$i=1;
$css_conf = array();
while(!$configuration->EOF) {
    	if (not_null($configuration->fields['use_function'])) {
	      $use_function = $configuration->fields['use_function'];
	      if (preg_match('/->/', $use_function)) {
	        $class_method = explode('->', $use_function);
	        if (!is_object(${$class_method[0]})) {
	          include(DIR_WS_CLASSES.$class_method[0].'.php');
	          ${$class_method[0]} = new $class_method[0]();
	        }
	        $cfgValue = call_function($class_method[1], $configuration->fields['configuration_value'], ${$class_method[0]});
	      } else {
	        $cfgValue = call_function($use_function, $configuration->fields['configuration_value']);
	      }
	    } else {
	      $cfgValue = $configuration->fields['configuration_value'];
	    }

    	if($configuration->fields['set_function']){
	        eval('$value_field = '.$configuration->fields['set_function'].'"'.htmlspecialchars($configuration->fields['configuration_value']).'");');
	    } else {
			if($configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BORDER_COLOR' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND_1' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND_2' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND_3' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND_4' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_HOVER_BACKGROUND_1' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_HOVER_BACKGROUND_2' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_HOVER_BACKGROUND_3' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_HOVER_BACKGROUND_4' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_FONT_COLOR' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_FONT_COLOR_HOVER' ||
				$configuration->fields['configuration_key'] =='CSS_BUTTON_BACKGROUND_HOVER' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BORDER_COLOR_HOVER' || 
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BORDER_COLOR' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND_1' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND_2' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND_3' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND_4' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_HOVER_BACKGROUND_1' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_HOVER_BACKGROUND_2' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_HOVER_BACKGROUND_3' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_HOVER_BACKGROUND_4' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_FONT_COLOR' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_FONT_COLOR_HOVER' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BACKGROUND_HOVER' ||
				$configuration->fields['configuration_key'] =='CSS_CART_BUTTON_BORDER_COLOR_HOVER') {
	        	$value_field = draw_input_field($configuration->fields['configuration_key'], $configuration->fields['configuration_value'], 'class="multiple" size="10"');
			} else {
				$value_field = draw_input_field($configuration->fields['configuration_key'], $configuration->fields['configuration_value'], 'size="20"');
			}
	     }

   if (strstr($value_field,'configuration_value'))
		$value_field = str_replace('configuration_value',$configuration->fields['configuration_key'],$value_field);
		$css_conf[$configuration->fields['configuration_key']] = array('key_name' => $configuration->fields['configuration_key'], 
																		'key_name_raw' => $configuration->fields['configuration_key'], 
																		'key_value' => $value_field, 
																		'key_value_raw' => $configuration->fields['configuration_value']);
	$i++;
	$configuration->MoveNext();
}

function kn($name) {
	if(!empty($name))
		return constant(strtoupper($name['key_name'].'_TITLE'));
}
function knr($name) {
	return $name['key_name_raw'];
}
function kd($name) {
	if(!empty($name))
		return constant(strtoupper($name['key_name'].'_DESC'));
}
function kv($name) {
	return $name['key_value'];
}
function kvr($name) {
	return str_replace('#', '', $name['key_value_raw']);
}
function tr_input($conf) {
	return '<td width="49%" valign="top"><table width="100%"><tr><td valign="top" width="40%">'.kn($conf).'</td>
			<td valign="top">'.kd($conf).'<br />'.kv($conf).'</td></tr></table></td>';
}
function tr_gradient_input($conf_1, $conf_2, $conf_3, $conf_4, $cart = false) {
	return '<td width="49%" valign="top"><table width="100%"><tr><td valign="top" width="40%">'.kn($conf_1).'</td><td valign="top"><table width="100%" align="left"><tr>
			<td>'.kd($conf_1).'<br />'.kv($conf_1).'<br />'.kd($conf_3).'<br />'.kv($conf_3).'</td>
			<td>'.kd($conf_2).'<br />'.kv($conf_2).'<br />'.kd($conf_4).'<br />'.kv($conf_4).'</td>
			</tr></table></td></tr></table>
			</td>';
}
function tr_spacer() {
	return '<td width="2%">&nbsp;</td>';
}
function tr_empty() {
	return '<td width="49%">&nbsp;</td>';
}

switch($_GET['page']) {
	case 'buttons':
		include(DIR_WS_MODULES.'css_styler/buttons.php');
		break;

	case 'cart_button':
		include(DIR_WS_MODULES.'css_styler/cart_button.php');
		break;

	case 'global_css':
		include(DIR_WS_MODULES.'css_styler/global_css.php');
		break;
}

if(!isset($_GET['page'])) {
	require(DIR_WS_INCLUDES.'metatag.php'); ?>
	<style type="text/css">
		tr.bt td {border-top: 1px solid #ccc;}
		tr.bt td table td {border-top: none 0;}
		tr.bg_grey td {background: #f1f1f1;}			
		<?php
		if(CSS_BUTTON_ACTIVE == 'true') {
			if(CSS_BUTTON_BACKGROUND_1 !='' || CSS_BUTTON_BACKGROUND_2 !=''){
				$background = ' url('.DIR_WS_CATALOG.'mercari_img.php?c1='.str_replace('#', '', CSS_BUTTON_BACKGROUND_1).'&c2='.str_replace('#', '', CSS_BUTTON_BACKGROUND_2).(CSS_BUTTON_BACKGROUND_3 !='' ? '&c3='.str_replace('#', '', CSS_BUTTON_BACKGROUND_3).'&c4='.str_replace('#', '', CSS_BUTTON_BACKGROUND_4):'').') repeat-x center left';
			} elseif(CSS_BUTTON_BACKGROUND_PIC !='')
				$background = ' url('.DIR_WS_CATALOG.'images/css_button_bg/'.CSS_BUTTON_BACKGROUND_PIC.') repeat-x 0 50%';
	
			$css = 'a span.css_img_button {background:'.CSS_BUTTON_BACKGROUND.$background.';';
	
			if(CSS_BUTTON_BORDER_WIDTH > 0 && CSS_BUTTON_BORDER_STYLE !='none') {
				$css .= 'border:'.CSS_BUTTON_BORDER_WIDTH.' '.CSS_BUTTON_BORDER_STYLE.' '.CSS_BUTTON_BORDER_COLOR.';';
			} else {
				$css .= 'border: 0;';
			}
	
			$css .= 'color:'.CSS_BUTTON_FONT_COLOR.';
				cursor:pointer;
				margin-bottom: 2px;
				font-family: '.CSS_BUTTON_FONT_FAMILY.';'
				.(CSS_BUTTON_FONT_SIZE!='' ? 'font-size:'.CSS_BUTTON_FONT_SIZE.';' : '').'
				font-size-adjust:none;
				font-stretch:normal;
				font-style:normal;
				font-variant:normal;
				font-weight:normal;
				display:inline-block;
				line-height:normal;'
				.((CSS_BUTTON_FONT_ITALIC == 'true') ? 'font-style: italic;' : '').
				'padding:0 6px 2px 6px;
				text-align:center !important;
				white-space:nowrap;';
			if(CSS_BUTTON_BORDER_RADIUS !='')
				$css .= '-moz-border-radius:'.CSS_BUTTON_BORDER_RADIUS.';-webkit-border-radius:'.CSS_BUTTON_BORDER_RADIUS.';border-radius:'.CSS_BUTTON_BORDER_RADIUS.';';
			if(CSS_BUTTON_FONT_SHADOW !='')
				$css .= 'text-shadow:'.CSS_BUTTON_FONT_SHADOW.';';
			if(CSS_BUTTON_MISC !='')
				$css .= CSS_BUTTON_MISC;
			$css .= '}';
	
			$css .= 'a span.css_img_button {
						line-height:2em;
					}';
			$css .= 'a:hover .css_img_button {';
	
			if(CSS_BUTTON_HOVER_BACKGROUND_1 !='' || CSS_BUTTON_HOVER_BACKGROUND_2 !='')
				$background_hover = ' url('.DIR_WS_CATALOG.'mercari_img.php?c1='.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_1).'&c2='.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_2).(CSS_BUTTON_HOVER_BACKGROUND_3 !='' ? '&c3='.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_3).'&c4='.str_replace('#', '', CSS_BUTTON_HOVER_BACKGROUND_4):'').') repeat-x center left';
			elseif(CSS_BUTTON_BACKGROUND_HOVER !='' || CSS_BUTTON_BACKGROUND_PIC_HOVER !='') {
				if(CSS_BUTTON_BACKGROUND_PIC_HOVER !='')
					$background_hover = ' url('.DIR_WS_CATALOG.'images/css_button_bg/'.CSS_BUTTON_BACKGROUND_PIC_HOVER.') repeat-x center left';
			}
			$css .= 'background:' . CSS_BUTTON_BACKGROUND_HOVER.$background_hover . ';';
			if(CSS_BUTTON_BORDER_COLOR_HOVER !='')
				$css .= 'border-color:'.CSS_BUTTON_BORDER_COLOR_HOVER.';';
			if(CSS_BUTTON_FONT_COLOR_HOVER!='')
				$css .= 'color:'.CSS_BUTTON_FONT_COLOR_HOVER.';';
			$css .= '}';
	
			$css .= '* html .css_img_button {padding: 1px 2px 2px 2px; }
					* html button.css_img_button { padding: 1px 2px 2px 2px; margin: -2px 1px;}';
			$css .= 'a.css_img_button:link,a.css_img_button:visited,a.css_img_button:active,a:hover .css_img_button { text-decoration: none; }';
			
			if(CSS_CART_BUTTON_BACKGROUND_1 !='' || CSS_CART_BUTTON_BACKGROUND_2 !='')
				$background = ' url('.DIR_WS_CATALOG.'mercari_img.php?h=40&c1='.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_1).'&c2='.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_2).(CSS_CART_BUTTON_BACKGROUND_3 !='' ? '&c3='.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_3).'&c4='.str_replace('#', '', CSS_CART_BUTTON_BACKGROUND_4):'').') repeat-x center left';
			elseif(CSS_CART_BUTTON_BACKGROUND_PIC !='')
				$background = ' url('.DIR_WS_CATALOG.'images/css_button_bg/'.CSS_CART_BUTTON_BACKGROUND_PIC.') repeat-x center left';
	
			$css .= 'input.css_cart_img_button { background:'.CSS_CART_BUTTON_BACKGROUND.$background.';';
	
			if(CSS_CART_BUTTON_BORDER_WIDTH > 0 && CSS_CART_BUTTON_BORDER_STYLE !='none') {
				$css .= 'border:'.CSS_CART_BUTTON_BORDER_WIDTH.' '.CSS_CART_BUTTON_BORDER_STYLE.' '.CSS_CART_BUTTON_BORDER_COLOR.';';
			} else {
				$css .= 'border: 0;';
			}
	
			$css .= 'color:'.CSS_CART_BUTTON_FONT_COLOR.';
				cursor:pointer;
				margin-bottom: 2px;
				font-family: '.CSS_CART_BUTTON_FONT_FAMILY.';'
				.(CSS_CART_BUTTON_FONT_SIZE!='' ? 'font-size:'.CSS_CART_BUTTON_FONT_SIZE.';' : '').'
				font-size-adjust:none;
				font-stretch:normal;
				font-style:normal;
				font-variant:normal;
				font-weight:normal;
				display:inline-block;
				line-height:normal;'
				.((CSS_CART_BUTTON_FONT_ITALIC == 'true') ? 'font-style: italic;' : '').
				'padding:6px;
				text-align:center !important;
				white-space:nowrap;';
			if(CSS_CART_BUTTON_BORDER_RADIUS !='')
				$css .= '-moz-border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';-webkit-border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';border-radius:'.CSS_CART_BUTTON_BORDER_RADIUS.';';
			if(CSS_BUTTON_FONT_SHADOW !='')
				$css .= 'text-shadow:'.CSS_CART_BUTTON_FONT_SHADOW.';';
			if(CSS_CART_BUTTON_MISC !='')
				$css .= CSS_CART_BUTTON_MISC;
			$css .= '}';
	
			$css .= 'input.css_cart_img_button:hover {';
			if(CSS_CART_BUTTON_HOVER_BACKGROUND_1 !='' || CSS_CART_BUTTON_HOVER_BACKGROUND_2 !='')
				$background_hover = ' url('.DIR_WS_CATALOG.'mercari_img.php?h=40&c1='.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_1).'&c2='.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_2).(CSS_CART_BUTTON_HOVER_BACKGROUND_3 !='' ? '&c3='.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_3).'&c4='.str_replace('#', '', CSS_CART_BUTTON_HOVER_BACKGROUND_4):'').') repeat-x center left';
			elseif(CSS_CART_BUTTON_BACKGROUND_HOVER !='' || CSS_CART_BUTTON_BACKGROUND_PIC_HOVER !='') {
				if(CSS_CART_BUTTON_BACKGROUND_PIC_HOVER !='')
					$background_hover = ' url('.DIR_WS_CATALOG.'images/css_button_bg/'.CSS_CART_BUTTON_BACKGROUND_PIC_HOVER.') repeat-x center left';
			}
			$css .= 'background:' . CSS_CART_BUTTON_HOVER_BACKGROUND_1.$background_hover . ';';
			if(CSS_CART_BUTTON_BORDER_COLOR_HOVER !='')
				$css .= 'border-color:'.CSS_CART_BUTTON_BORDER_COLOR_HOVER.';';
			if(CSS_CART_BUTTON_FONT_COLOR_HOVER!='')
				$css .= 'color:'.CSS_CART_BUTTON_FONT_COLOR_HOVER.';';
			$css .= '}';
	
			$css .= '* html .css_cart_img_button { padding: 1px 2px 2px 2px; }';
			
		} elseif (CSS_BUTTON_ACTIVE == 'text') {
			$css  = 'a span.css_img_button {';
			$css .= 'border: none 0;';
			$css .= 'background: none;';
			$css .= 'color: #444;';
			$css .= 'cursor: pointer;';
			$css .= 'margin: 2px 5px;';
			$css .= '}';
			$css .= 'a:hover .css_img_button {';
			$css .= 'color:#000;';
			$css .= 'text-decoration:underline;';
			$css .= '}';
		}
		echo $css;
		?>
		.area_shape {position: absolute;z-index: 10;cursor:pointer;}
		.area_shape:hover {background: #E6DA32;opacity:.4}
	</style>
	</head>
	<body>
	<?php require(DIR_WS_INCLUDES.'header.php'); ?>
	<div id="wrapper">
		<table class="outerTable" cellpadding="0" cellspacing="0">
			<tr>
				<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
					<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
				</td>
				<td class="boxCenter" valign="top">
					<table width="100%" cellspacing="0" cellpadding="2">
						<tr>
							<td>
								<table class="table_pageHeading" cellspacing="0" cellpadding="0" width="100%">
									<tr>
										<td class="pageHeading" width="100%">
											<?php echo HEADING_TITLE; ?>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td>
								<button class="button" onclick="dialogBox('?page=buttons', '90%', '600', 'Globale Button Einstellung', 'true')">
									Buttons
								</button> 
								<button class="button" onclick="dialogBox('?page=cart_button', '90%', '600', 'Warenkorb Button Einstellung', 'true')">
									Warenkorb Button
								</button>
								<!--button class="button" onclick="dialogBox('?page=global_css', '1000', '750', 'Globale CSS Einstellungen', 'true')">
									Globale CSS Einstellungen
								</button-->
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	
	<script type="text/javascript">
		function dialogBox(url, w, h, title, save) {
			<?php if(isset($_SESSION['customer_id'])) { ?>
				if(save == 'true') {
					var extra_button = {"<?php echo BUTTON_SAVE ?>":function(){$("#dialog_form").submit();},"<?php echo BUTTON_CANCEL ?>":function(){$(this).dialog("close");}};
				} else {var extra_button = '';}
				
				var url = url;
	            var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
	            
	            dialog.dialog({
	                close: function(event, ui) {dialog.remove();},
	                modal: true,
	                title: title,
	                buttons: extra_button,
	                width: w,
	                height: h
	            });
	            dialog.load(url,{},function (responseText, textStatus, XMLHttpRequest){
	            	dialog.removeClass('loading');
	            	$('.ui-dialog-content').css({backgroundImage:'none'});
	            	$(".multiple").miniColors();
	            });
	            $('.ui-dialog').css({position:"fixed"});
			<?php } else { ?>
				window.location.href='<?php echo catalog_href_link('login.php', '', 'SSL'); ?>';
			<?php } ?>
			return false;
		}
	</script>
	<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
	</body>
	</html>
	<?php require(DIR_WS_INCLUDES.'application_bottom.php');
}